-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fix: allow non-prerendered API endpoint calls during reroute when prerendering #13616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 7339c10 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
I ran into an error testing this locally with a prerendered
I was able to 'fix' it by using --git a/packages/kit/src/runtime/server/respond.js b/packages/kit/src/runtime/server/respond.js
index 81b30e075..5b1ec0d7d 100644
--- a/packages/kit/src/runtime/server/respond.js
+++ b/packages/kit/src/runtime/server/respond.js
@@ -34,6 +34,7 @@ import {
strip_resolution_suffix
} from '../pathname.js';
import { with_event } from '../app/server/event.js';
+import { create_universal_fetch } from './page/load_data.js';
/* global __SVELTEKIT_ADAPTER_NAME__ */
/* global __SVELTEKIT_DEV__ */
@@ -181,6 +182,13 @@ export async function respond(request, options, manifest, state) {
});
}
+ /** @type {import('types').RequiredResolveOptions} */
+ let resolve_opts = {
+ transformPageChunk: default_transform,
+ filterSerializedResponseHeaders: default_filter,
+ preload: default_preload
+ };
+
let resolved_path;
const prerendering_reroute_state = state.prerendering?.inside_reroute;
@@ -191,7 +199,10 @@ export async function respond(request, options, manifest, state) {
// reroute could alter the given URL, so we pass a copy
resolved_path =
- (await options.hooks.reroute({ url: new URL(url), fetch: event.fetch })) ?? url.pathname;
+ (await options.hooks.reroute({
+ url: new URL(url),
+ fetch: create_universal_fetch(event, state, [], false, resolve_opts)
+ })) ?? url.pathname;
} catch {
return text('Internal Server Error', {
status: 500
@@ -277,13 +288,6 @@ export async function respond(request, options, manifest, state) {
}
}
- /** @type {import('types').RequiredResolveOptions} */
- let resolve_opts = {
- transformPageChunk: default_transform,
- filterSerializedResponseHeaders: default_filter,
- preload: default_preload
- };
-
/** @type {import('types').TrailingSlash} */
let trailing_slash = 'never'; Not sure if you have any better ideas? I put my repro up here: https://github.com/Rich-Harris/repro-kit-13616 |
Good catch! This isn't exactly a regression from this fix but a different bug, but good to fix it regardless. I adjusted the logic in the endpoint to add the response to the prerendered dependencies if needed. Will self-merge once green. |
There's a bug within
reroute
when prerendering:/
and on it is a link<a href="/foo">..
/api/reroute
for example, using the provided fetchTo fix this we need to add a new boolean to the prerendering state to not error in those situations (and also to allow query strings)
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.